package com.example.juc;

import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class StreamTest {
    public static void main(String[] args) {
//        ArrayList<String> arrays = new ArrayList<>();
//        arrays.add("S");arrays.add("h");arrays.add("h");arrays.add("sb");
//        arrays.add("S");arrays.add("h");arrays.add("h");arrays.add("sb");
//        System.out.println(arrays.toString());
//        filter过滤使用
//        Stream<String> s = arrays.stream().filter(str -> {
//           return str.length()>=2;
//        });
//        List<String> collect = s.collect(Collectors.toList());
//        System.out.println(collect.toString());
//          stream.distinct 去重
//        Stream<String> distinct = arrays.stream().distinct();
//        List<String> collect = distinct.collect(Collectors.toList());
//        System.out.println(collect.toString());
//
        Student student = new Student("1", 5);
        Student student1 = new Student("1", 3);
        Student student2 = new Student("2", 2);
        ArrayList<Student> students = new ArrayList<>();
        students.add(student);
        students.add(student1);
        students.add(student2);
//        List<Student> collect = students.stream().filter(student3 -> {
//           return student3.getName().equals("1");
//        }).collect(Collectors.toList());
//        System.out.println(collect.toString());
//        Limit测试
//        Stream<Student> limit = students.stream().limit(1);
//        List<Student> collect = limit.collect(Collectors.toList());
//        for (Student student3 : collect) {
//            System.out.println(student);
//        }
//        skip跳过数据测试
//        System.out.println(students.stream().skip(1).collect(Collectors.toList()).toString());
//        map测试
//        System.out.println(students.stream()
//                .map(stu->{
//                    return stu;
//                }).collect(Collectors.toList()));
//        Stream<String> stringStream = students.stream().flatMap(stu -> {
//            ArrayList<String> names = new ArrayList<>();
//            names.add(stu.getName());
//            return names.stream();
//        });
//        Stream<String> skip = stringStream.skip(1);
//          skip.forEach(s -> {
//              System.out.println(s );
//          });

//        System.out.println(students.stream().sorted((o, o1) -> {
//            return o.getId() - o.getId();
//        }).collect(Collectors.toList()).toString());
//        boolean b = students.stream().anyMatch(s -> {
//            return s.getId() > 6;
//        });
//        System.out.println(b);

//        boolean b = students.stream().noneMatch(s -> {
//            return s.getId() > 10;
//        });
//        System.out.println(b);
//        for (int i = 0; i < 10; i++) {
//            System.out.println(students.stream().findAny().get().toString());
//        }
//        Set<Student> collect = students.stream().collect(Collectors.toSet());
//        for (Student student3 : collect) {
//            System.out.println(student3);
//        }
//        System.out.println(students.stream().count());
        Optional<Student> reduce = students.stream().reduce((sum, list) -> {
           return sum;
        });
        System.out.println(reduce.get());
    }
}
